import { Tooltip } from 'antd';

import pageStyles from '@/common/pageLayout.less';
import { getColorTextLoadMap } from '@/utils';

/**
 * @renderOverflowText
 * @description 处理文字溢出
 * @param text 值
 * @param isShowTooltip 是否溢出隐藏并且加Tooltip
 * @returns
 */
export const renderOverflowText = (text: string | number | null, isShowTooltip = false) => {
  const index = ['1', '0'].indexOf(String(text) || '');
  const { colorText, color } = getColorTextLoadMap(String(text));
  const info = {
    word: colorText == 'undefined' || colorText == 'null' || !colorText ? '--' : colorText,
    color: color,
  };
  if (index != -1) {
    info.word = index == 1 ? '是' : '否';
    info.color = index == 1 ? '#409eff' : 'red';
  }
  if (isShowTooltip && info.word != '--') {
    return (
      <Tooltip title={info.word}>
        <span className={pageStyles['over-flow-hidden']} style={{ color: info.color }}>
          {info.word}
        </span>
      </Tooltip>
    );
  } else {
    return <span style={{ color: info.color }}>{info.word}</span>;
  }
};
/**
 * 排序
 * */
export const getSorter = (prev: Record<string, any>, next: Record<string, any>): number => (prev > next ? 1 : -1);
